package sg.edu.nus.iss.billing.common.dataHandling;

public class DataFormat {
	
	public  final String getFormattedLine(String text, int lineLength, int align) {
        if (text == null) {
            text = "";
        }

        int padding = lineLength - text.length();
        int rightPad;
        int leftPad;
        switch (align) {
            case 2:
                int carry = padding % 2;

                padding -= carry;

                leftPad = rightPad = padding / 2;

                rightPad += carry;

                break;
            case 3:
                leftPad = padding;
                rightPad = 0;
                break;
            default:
                leftPad = 0;
                rightPad = padding;
        }

        StringBuffer result = new StringBuffer();

        for (int i = 0; i < leftPad; ++i) {
            result.append(' ');
        }

        result.append(text);

        for (int i = 0; i < rightPad; ++i) {
            result.append(' ');
        }

        return result.toString();
    }

}
